//
//  main.cpp
//  B. Spreadsheets
//
//  Created by Zachary Brody on 12/15/13.
//  Copyright (c) 2013 Zachary Brody. All rights reserved.
//

#include <iostream>
#include <sstream>
#include <string>
#include <math.h>

using namespace std;

int power (int one, int two)
{
    int tempInt = one;
    for (int i = 0; i < two - 1; i++) {
        tempInt *= one;
    }
    return tempInt;
}

bool isNum (char origChar)
{
    return origChar == '1' || origChar == '2' || origChar == '3' || origChar == '4' || origChar == '5' || origChar == '6' || origChar == '7' || origChar == '8' || origChar == '9' || origChar == '0';
}

bool isOrigNumSystem (string origString)
{
    bool isOrigSystem = true;
    if (origString[0] == 'R' && isNum(origString[1])) {
        for (int i = 0; i< origString.length(); i++) {
            if (origString[i] == 'C') {
                if (isNum(origString[i-1])) {
                    isOrigSystem = false;
                }
            }
        }
    }
    
    return isOrigSystem;
}

string origNumToNew (string origString)
{
    stringstream tempStream;
    string tempString;
    int index = 0;
    while (!isNum(origString[index])) {
        index ++;
    }
    tempStream << 'R';
    for (int i = index; i < origString.length(); i++) {
        tempStream << origString[i];
    }
    tempStream << 'C';
    double column = 0;
    if (index == 1) {
        column = (int)(origString[0]) - 64;
    } else {
        for (int i = 0; i < index; i++) {
            column += ((int)(origString[i]) - 64) * ((index - i - 1) != 0 ? (power(26, (index - i - 1))): 1);
        }
    }
    tempStream << column;
    tempStream >> tempString;
    return tempString;
}

string newNumtoOrig (string origString)
{
    double row = 0;
    stringstream tempRowStream;
    int index = 1;
    while (origString[index] != 'C') {
        index ++;
    }
    for (int i = 1; i < index; i++) {
        tempRowStream << origString[i];
    }
    tempRowStream >> row;
    stringstream tempColumnString;
    for (int i = index + 1; i < origString.length(); i++) {
        tempColumnString << origString[i];
    }
    double column;
    tempColumnString >> column;
    stringstream tempStream;
    int tempInt = 0;
    while (true) {
        if(column < power(26, tempInt))
        {
            tempInt --;
            break;
        }
        tempInt ++;
    }
    int newTempInt = 0;
    while (column != 0) {
        if (column <= 26) {
            tempStream << (char)(column + 64);
            column = 0;
        } else {
            tempStream << (char)((column - ((int)column % power(26, tempInt - newTempInt)))/power(26, tempInt - newTempInt) + 64);
            column -= (column - ((int)column % power(26, tempInt-newTempInt)));
        }
        newTempInt ++;
    }
    string tempString;
    tempStream << row;
    tempStream >> tempString;
    return tempString;
}


int main(int argc, const char * argv[])
{
    cin.precision(30);
    cout.precision(30);
    double numCells;
    cin >> numCells;
    for (int i = 0; i < numCells; i++) {
        string tempString;
        cin >> tempString;
        if (isOrigNumSystem(tempString)) {
            cout << origNumToNew(tempString) << "\n";
        } else {
            cout << newNumtoOrig(tempString) << "\n";
        }
    }
    return 0;
}

